import numpy as np
import tensorflow as tf

x = tf.Variable(tf.random_normal([3, 4], stddev=1))

y = tf.Variable(tf.random_normal([3, 4], stddev=1))

B = tf.placeholder(dtype=tf.int32, shape=[2])
C = tf.gather_nd(x, B)

def func(x):
  return x * 2

init = tf.global_variables_initializer()

with tf.Session() as sess:
  sess.run(init)
  print("====================")
  print(sess.run(x))
  print("====================")
  print(sess.run(y))
  print("====================")
  aa = []
  for i in range(3):
    aa.append([])
    for j in range(4):
      _a = func(sess.run(C, feed_dict={B:[i,j]}))
      print(_a)
      aa[i].append(_a)
  print("====================")
  print(aa)  
  op = tf.assign(y, aa)
  sess.run(op)
  print("====================")
  print(sess.run(y))


